package com.example.online_exam_system.dao;

import com.example.online_exam_system.dto.TeacherregDto;
import com.example.online_exam_system.entity.Teacher;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;


/**
 * (Teacher)表数据库访问层
 *
 * @author lianglong@asiainfo.com
 * @since 2021-11-25 14:09:53
 */
public interface TeacherDao {

    /**
     * 通过ID查询单条数据
     *
     * @param teacherid 主键
     * @return 实例对象
     */
    @Select("select * from teacher where teacherid = #{teacherid}")
    Teacher queryById(Object teacherid);

    /**
     * 查询指定行数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    List<Teacher> queryAllByLimit(@Param("offset") int offset, @Param("limit") int limit);


    /**
     * 通过实体作为筛选条件查询
     *
     * @param teacher 实例对象
     * @return 对象列表
     */
    List<Teacher> queryAll(Teacher teacher);

    /**
     * 新增数据
     *
     * @param teacher 实例对象
     * @return 影响行数
     */
    int insert(Teacher teacher);

    @Insert("INSERT INTO teacher (\n" +
            "  password, realname,regtime, MAILNUMBER)\n" +
            "VALUES\n" +
            "  (#{inParam.password},#{inParam.username},#{inParam.regtime},#{inParam.mailnumber});")
    int insert(@Param("inParam") TeacherregDto teacherregDto);

    /**
     * 批量新增数据（MyBatis原生foreach方法）
     *
     * @param entities List<Teacher> 实例对象列表
     * @return 影响行数
     */
    int insertBatch(@Param("entities") List<Teacher> entities);

    /**
     * 批量新增或按主键更新数据（MyBatis原生foreach方法）
     *
     * @param entities List<Teacher> 实例对象列表
     * @return 影响行数
     */
    int insertOrUpdateBatch(@Param("entities") List<Teacher> entities);

    /**
     * 修改数据
     *
     * @param teacher 实例对象
     * @return 影响行数
     */
    int update(Teacher teacher);

    /**
     * 通过主键删除数据
     *
     * @param teacherid 主键
     * @return 影响行数
     */
    int deleteById(Object teacherid);

    @Select("select * from teacher where realname = #{inParam.username} and password = #{inParam.password}")
    List<Map<String, Object>> queryByuserName(@Param("inParam") Map<String, Object> inParam);

    @Select("select teacherid,realname,serialnumber,mailnumber from teacher where realname = #{realname}")
    Map<String, Object> getTeacherInfo(String realname);

    @Select("select teacherid from teacher where realname =#{realname}")
    String getTeacherId(String realname);

    @Select("select password from teacher where realname =#{inParam.username}")
    String getPassword(@Param("inParam")Map<String, Object> inParam);

    @Update("update teacher set password =#{inParam.password2}, serialnumber =#{inParam.serialnumber},mailnumber=#{inParam.mailnumber} " +
            "where realname= #{inParam.username}")
    int updateTeacherInfo(@Param("inParam")Map<String, Object> inParam);

    @Select("select realname from teacher where teacherid = #{teacherid}")
    Map<String, Object> queryByUserId(@Param("teacherid")String teacherId);

    @Select("SELECT teacherid,realname,serialnumber,mailnumber,regtime FROM teacher")
    List<Map<String, Object>> getAllInfo();
}

